package org.ysu.shoeShopping.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.AdminsDao;
import org.ysu.shoeShopping.entity.Admins;
import org.ysu.shoeShopping.service.AdminsService;

import java.util.List;

/**
 * 后台用户表(Admins)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 14:51:48
 */
@Service("adminsService")
public class AdminsServiceImpl implements AdminsService
{
    @Autowired
    private AdminsDao adminsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param aid 主键
     * @return 实例对象
     */
    @Override
    public org.ysu.shoeShopping.entity.Admins queryById(Integer aid) {
        return this.adminsDao.queryById(aid);
    }

    /**
     * 分页查询
     *
     * @param admins 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<org.ysu.shoeShopping.entity.Admins> queryByPage(org.ysu.shoeShopping.entity.Admins admins, PageRequest pageRequest) {
        long total = this.adminsDao.count(admins);
        return new PageImpl<>(this.adminsDao.queryAllByLimit(admins, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param admins 实例对象
     * @return 实例对象
     */
    @Override
    public org.ysu.shoeShopping.entity.Admins insert(org.ysu.shoeShopping.entity.Admins admins) {
        this.adminsDao.insert(admins);
        return admins;
    }

    /**
     * 修改数据
     *
     * @param admins 实例对象
     * @return 实例对象
     */
    @Override
    public org.ysu.shoeShopping.entity.Admins update(org.ysu.shoeShopping.entity.Admins admins) {
        this.adminsDao.update(admins);
        return this.queryById(admins.getAid());
    }

    /**
     * 通过主键删除数据
     *
     * @param aid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer aid) {
        return this.adminsDao.deleteById(aid) > 0;
    }

    @Override
    public Admins findByAccountAndApwd(String acount, String apwd)
    {
        return this.adminsDao.findByAccountAndApwd(acount,apwd);
    }

    @Override
    public Admins findByAccount(String acount)
    {
        return this.adminsDao.findByAccount(acount);
    }


@Override
    public List<Admins> findAdminsAll(){
        return this.adminsDao.findAdminsAll();
}

}
